/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.just.dusin.ooii.util;

import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 *
 * @author Administrator
 */
public class DeviceSimulator {
    static double severeOverfulfillLevel=0.1;  //严重超产线
    private double outputof5min;    //标准5分钟产量
    private double probabilityOfOverfulfill;//超产概率
    private double probabilityOfSevereOverfulfill;//严重超产概率
    private double currentOutputOfTotal=0;  //当前累计产量
    private Calendar timer = null;

    public Calendar getTimer() {
        return timer;
    }

    public DeviceSimulator(double o5,double po,double pso,int year,int month,int day){
        outputof5min = o5;
        probabilityOfOverfulfill=po;
        probabilityOfSevereOverfulfill=pso;
        timer = Calendar.getInstance();
        timer.set(year, month-1,day,0,0,0);        
    }
    
    public double getCurrentOutputOfTotal() {
        
        timer.add(Calendar.MINUTE, 5);
        if(timer.get(Calendar.MINUTE)==5)
            currentOutputOfTotal=0;
        
        if(Math.random()<probabilityOfSevereOverfulfill)
                currentOutputOfTotal+=outputof5min+outputof5min*(severeOverfulfillLevel)+outputof5min*Math.random()*0.25;
        else if(Math.random()<probabilityOfOverfulfill){
                currentOutputOfTotal+=outputof5min+outputof5min*(severeOverfulfillLevel)*Math.random();                
        }
        else
            currentOutputOfTotal+=outputof5min-outputof5min*Math.random()*0.25;
//currentOutputOfTotal+=outputof5min;
        DecimalFormat df = new DecimalFormat("#####");
        String strOutput =df.format(currentOutputOfTotal);
        return Double.parseDouble(strOutput);
    }   
    
    public double getCurrent5MinOutput(){
        double o5;   //5分钟产量
        if(Math.random()<probabilityOfSevereOverfulfill)
                o5=outputof5min+outputof5min*(severeOverfulfillLevel)+outputof5min*Math.random()*0.25;
        else if(Math.random()<probabilityOfOverfulfill){
                o5=outputof5min+outputof5min*(severeOverfulfillLevel)*Math.random();                
        }
        else
            o5=outputof5min-outputof5min*Math.random()*0.05;
//currentOutputOfTotal+=outputof5min;
        return o5;
    }
    
    public String getTimeString(){
        String timeString;
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd/HH:mm");
        
        timeString = sdf.format(timer.getTime());
        return timeString;
    }
    
    
    public void reset(){
        currentOutputOfTotal=0;
    }
}
